package com.example.demo.datagen;

import com.example.demo.block.ModBlocks;
import com.example.demo.item.ModItems;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.loot.entry.LootPoolEntry;
import net.minecraft.loot.function.ApplyBonusLootFunction;
import net.minecraft.loot.function.SetCountLootFunction;
import net.minecraft.loot.provider.number.UniformLootNumberProvider;

public class ModLootTablesProvider extends FabricBlockLootTableProvider {
    public ModLootTablesProvider(FabricDataOutput fabricDataOutput) {
        super(fabricDataOutput);
    }

    @Override
    public void generate() {
        addDrop(ModBlocks.EXAMPLE_BLOCK);
        addDrop(ModBlocks.RAW_EXAMPLE_BLOCK);
        addDrop(ModBlocks.FIRE_ETHER);
        addDrop(ModBlocks.EXAMPLE_ORE_BLOCK, copperOreLikeDrops(ModBlocks.EXAMPLE_ORE_BLOCK, ModItems.EXAMPLE_ITEM));
    }


    public LootTable.Builder copperOreLikeDrops(Block drop, Item item) {
        return dropsWithSilkTouch(
                drop, this.applyExplosionDecay(
                        drop,
                        ItemEntry.builder(item)
                                .apply(SetCountLootFunction.builder(UniformLootNumberProvider.create(2.0F, 5.0F)))
                                .apply(ApplyBonusLootFunction.oreDrops(Enchantments.FORTUNE))
                )
        );
    }
}
